<?php


namespace App\Http\Controllers\System;


use App\Http\Controllers\Controller;
use App\Repositories\System;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class SystemController extends Controller
{
    /**
     * @var System
     */
    private $system;

    /**
     * SystemController constructor.
     * @param System $system
     */
    public function __construct(System $system)
    {
        $this->system = $system;
    }

    /**
     * @param $group
     * @return \Illuminate\Http\JsonResponse
     */
    public function show($group)
    {
        return $this->response(
            $this->system->getForGroup($group)
        );
    }

    /**
     * @param Request $request
     * @param $group
     * @return \Illuminate\Http\JsonResponse
     */
    public function update(Request $request, $group)
    {
        return $this->response(
            DB::transaction(function () use ($group, $request) {
                $this->system->putForGroup($group, $request->toArray());
            })
        );
    }
}
